package com.qf.osmproduct.product.controller;

import cn.hutool.core.lang.tree.Tree;
import com.qf.common.core.annotation.NoLogin;
import com.qf.common.core.common.R;
import com.qf.common.core.entity.product.Product;
import com.qf.osmproduct.product.param.HomeGoodsParam;
import com.qf.osmproduct.product.service.ProductService;
import com.qf.osmproduct.product.vo.HomeRECVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 天--道--酬--勤
 *
 * @author LiangGaoQiang
 * @ClassName ProductController
 * @Date: 2025/6/9 11:07
 * @Description: 描述
 */

@RestController
@RequestMapping("/Home")
public class HomeController {

    @Resource
    private ProductService productService;


    /**
     * 获取商品列表
     *
     * @return R
     */
    @GetMapping("/getHomeShowTreeGoods")
    @NoLogin
    public R getTreeList(HomeGoodsParam homeGoodsParam) {
        List<Tree<String>> productVO = productService.getList(homeGoodsParam);
        if (productVO.isEmpty()) {
            return R.fail();
        }
        return R.ok(productVO);
    }


    /**
     * 获取首页商品的图片列表
     * @return R
     */
    @GetMapping("/getHomeREC")
    public R getHomeREC(){
        // 获取首页推荐商品
        HomeRECVO homeRECVO = productService.getHomeREC();

        // 首页推荐商品为空
        if (homeRECVO == null){
            return R.fail();
        }
        // 返回首页推荐商品
        return R.ok(homeRECVO);
    }


    /**
     * 获取首页展示商品列表
     *
     * @return R
     */
    @GetMapping("/getHomeShowGoods")
    public R  getHomeShowGoods(HomeGoodsParam homeGoodsParam){
        // 获取首页展示商品
        List<Product> homeShowGoods = productService.getHomeShowGoods(homeGoodsParam);
        if (homeShowGoods.isEmpty()){
            return R.fail();
        }
        return R.ok(homeShowGoods);
    }


}
